//
//  SWPresentationController.swift
//  SinaWeibo
//
//  Created by wszyxc on 16/7/21.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

import UIKit

class SWPresentationController: UIPresentationController {
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
        
        
        
    }
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        //1.修改视图的尺寸
        //containerView--容器视图
        //presentedView--展现视图
        
        presentedView()?.frame = CGRectMake(100, 56, 200, 250)
        
        //2.添加蒙版,放在containerView上面
        containerView?.insertSubview(coverView, atIndex: 0)
        
        //3.添加手势
        let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "coverTap")
        
        coverView.addGestureRecognizer(tap)
        
    }
    
    //懒加载coverView
    private lazy var coverView:UIView = {
        
        let coverView = UIView()
        
        coverView.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
        
        coverView.frame = ScreenBounds
        


        return coverView
    }()
    
    
   //手势和按钮点击一样,也是runLoop去执行的
  @objc  private func coverTap(){
    
    
      //  isAnima = false
        //让presentedView消失
    
        print("点击遮罩")
    
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    
    
    }
    

    

}
